#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

long long minimumRemoval(vector<int>& beans) {
    int n = beans.size();
    sort(beans.begin(), beans.end());
    long long total = accumulate(beans.begin(), beans.end(), 0LL);
    long long res = total;
    for (int i = 0; i < n; i++)
        res = min(res, total - (long long)beans[i] * (n - i));
    return res;
}